﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace MTO.Library.Domain
{
    public class ProductCategory
    {
        public ProductCategory()
        {
            Children = new List<ProductCategory>();
            Products = new List<Product>();
        }

        public int ProductCategoryId { get; set; }

        [Required(ErrorMessage = "Name must be provided")]
        [StringLength(255, ErrorMessage = "Name must be 255 characters or fewer")]
        public string Name { get; set; }

        public int ParentId { get; set; }

        /// <summary>
        /// many-to-one from child ProductCategory to parent ProductCategory
        /// </summary>
        [Display(Name = "Parent Category")]
        public virtual ProductCategory Parent { get; set; }

        /// <summary>
        /// many-to-many between ProductCategory and Product
        /// </summary>
        public virtual IList<Product> Products { get; protected set; }

        /// <summary>
        /// one-to-many from parent ProductCategory to children ProductCategory
        /// </summary>
        public virtual IList<ProductCategory> Children { get; protected set; }
    }
}
